/**
 * Created by Administrator on 2016/6/6.
 */
var zaz;
var val;
var user_name;
var user_id;
var fingercode;
var fingerpic;

$.ajaxSetup({
    cache: false //关闭AJAX相应的缓存
});

function createOcx() {
    zaz = document.createElement("object");
    zaz.setAttribute("id", "zaz");
    zaz.setAttribute("classid", "clsid:74DCA74B-4B00-44CE-AAFA-D66902C2C6B3");
    zaz.setAttribute("width", "0");
    zaz.setAttribute("height", "0");
}

function get_username_userid() {
    $.post("/username", function (data) {
        var aa = data.split(":");
        // self.parent.frames["topFrame"].document.getElementById("username").text(aa[0]);
        user_name = aa[0];
        user_id = aa[1];
        // alert(user_name + ":" + user_id);
        return false;
    });
}

function setval(data) {
    val = data;
    return false;
}

function delete1() {
    var href = ( "/users/" + val );
    $("#DELETE").attr("action", href).submit();
    location.href = '/showUsers';
    return false;
}

function getfinger_code() {
    zaz.LIVESCANGetFPRawData(0);
    var bbb = zaz.FPFeatureExtract(43, 99);

    if (bbb == "1") {
        fingercode = zaz.LIVESCANGetFpchar(0);
    } else {
        alert(zaz.LIVESCANGetErrorInfo(bbb));
    }
}

function getfinger_pic() {
    var aaa = zaz.LIVESCANGetFPBmpData(0);
    if (aaa == "1") {
        fingerpic = zaz.LIVESCANGetFpbmpbase64(1);
    } else {
        alert(zaz.LIVESCANGetErrorInfo(aaa));
    }
}

function get_all_finger() {
    $.post("/fingers/" + user_id, function (data) {
        $.each(data, function () {
            $("#f" + this.fingerId + " img").attr("src",
                "data:image/jpg;base64," + this.fingerPic);
            // $("#f" + this.fingerId + " img").attr("height", '50%');
            // $("#f" + this.fingerId + " img").attr("width", '50%');
        });
        return false;
    });
}

function edit_finger(data) {
    getfinger_code();
    getfinger_pic();

    alert(fingerpic);
    alert(fingercode);

    $("#f" + data + " img").attr("src",
        "data:image/jpg;base64," + fingerpic);

    updatefinger(data);
}

function updatefinger(data) {
    $.ajax(
        {
            url: "/finger", type: "PUT",
            contentType: "application/json;charset=UTF-8",
            data: JSON.stringify(
                {
                    // 	            id : null,operatorTime : null,
                    userId: user_id, fingerId: data, fingerCode: fingercode,
                    fingerPic: fingerpic
                }), success: function (data) {
            $.each(data, function (key, val) {
//                            $("#info").attr("class", key);
//                            $("#info").text(val);
                alert(key + ":" + val);
            });
        }
        });
}

$(function () {
    //图片选中
    $(".imglist li").click(function () {
        $(".imglist li.selected").removeClass("selected");
        $(this).addClass("selected");
    });
    //导航切换
    $(".menuson li").click(function () {
        $(".menuson>li.active").removeClass("active");
        $(this).addClass("active");

    });
    //子导航切换
    $(".menuson .header").click(function () {
        var $parent = $(this).parent();
        $(".menuson>li.active").not($parent).removeClass("active open").find('.sub-menus').hide();

        $parent.addClass("active");
        if (!!$(this).next('.sub-menus').size()) {
            if ($parent.hasClass("open")) {
                $parent.removeClass("open").find('.sub-menus').hide();
            } else {
                $parent.addClass("open").find('.sub-menus').show();
            }
        }
    });
    // 三级菜单点击
    $('.sub-menus li').click(function (e) {
        $(".sub-menus li.active").removeClass("active")
        $(this).addClass("active");
    });

    $('.title').click(function () {
        var $ul = $(this).next('ul');
        $('dd').find('.menuson').slideUp();
        if ($ul.is(':visible')) {
            $(this).next('.menuson').slideUp();
        } else {
            $(this).next('.menuson').slideDown();
        }
    });
    //模态框
    $(".click").click(function () {
        $(".tip").fadeIn(200);
    });
    $(".tiptop a").click(function () {
        $(".tip").fadeOut(200);
    });
    $(".sure").click(function () {
        $(".tip").fadeOut(100);
    });
    $(".cancel").click(function () {
        $(".tip").fadeOut(100);
    });

});

$(document).ready(function () {
    zaz = self.parent.zaz;
    user_name = self.parent.user_name;
    user_id = self.parent.user_id;
    $("#username").text(user_name);
    // alert(zaz + ":" + user_name + ":" + user_id);
});
